package com.qf.card.controller;


import com.github.pagehelper.PageInfo;

import com.qf.card.pojo.BankCard;
import com.qf.card.pojo.Card;
import com.qf.card.service.BankCardService;
import com.qf.common.entity.Result;
import com.qf.common.entity.StatusCode;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/****
 * @Author:shenkunlin
 * @Description:
 * @Date 2019/6/14 0:18
 *****/
@Api(value = "BankCardController")
@RestController
@RequestMapping("/bankCard")
@CrossOrigin
public class BankCardController {

    @Autowired
    private BankCardService bankCardService;

    /***
     * BankCard分页条件搜索实现
     * @param bankCard
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false) @ApiParam(name = "BankCard对象",value = "传入JSON数据",required = false) BankCard bankCard, @PathVariable  int page, @PathVariable  int size){
        //调用BankCardService实现分页条件查询BankCard
        PageInfo<BankCard> pageInfo = bankCardService.findPage(bankCard, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * BankCard分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用BankCardService实现分页查询BankCard
        PageInfo<BankCard> pageInfo = bankCardService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param bankCard
     * @return
     */
    @PostMapping(value = "/search" )
    public Result<List<BankCard>> findList(@RequestBody(required = false) @ApiParam(name = "BankCard对象",value = "传入JSON数据",required = false) BankCard bankCard){
        //调用BankCardService实现条件查询BankCard
        List<BankCard> list = bankCardService.findList(bankCard);
        return new Result<List<BankCard>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Integer id){
        //调用BankCardService实现根据主键删除
        bankCardService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改BankCard数据
     * @param bankCard
     * @param id
     * @return
     */
    @PutMapping(value="/{id}")
    public Result update(@RequestBody @ApiParam(name = "BankCard对象",value = "传入JSON数据",required = false) BankCard bankCard,@PathVariable Integer id){
        //设置主键值
        bankCard.setPkBankId(id);
        //调用BankCardService实现修改BankCard
        bankCardService.update(bankCard);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增BankCard数据
     * @param bankCard
     * @return
     */
    @PostMapping
    public Result add(@RequestBody  @ApiParam(name = "BankCard对象",value = "传入JSON数据",required = true) BankCard bankCard){
        //调用BankCardService实现添加BankCard
        bankCardService.add(bankCard);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询BankCard数据
     * @param userId
     * @return
     */
    @GetMapping("/{id}")
    public Result<List<BankCard>> findById(@PathVariable("id") Integer userId){
        //调用BankCardService实现根据主键查询BankCard

        //Map<String,Object> searchMap = new HashMap<>();
        //
        //if (!"all".equals(userId)){
        //    searchMap.put("spuId",userId);
        //}
        //searchMap.put("status","1");

        BankCard bankCard = new BankCard();
        bankCard.setUserId(userId);
        bankCard.setBranchState("1");

        List<BankCard> bankCardList = bankCardService.findList(bankCard);
        return new Result<List<BankCard>>(true,StatusCode.OK,"查询成功",bankCardList);
    }

    /***
     * 查询BankCard全部数据
     * @return
     */
    @GetMapping
    public Result<List<BankCard>> findAll(){
        //调用BankCardService实现查询所有BankCard
        List<BankCard> list = bankCardService.findAll();
        return new Result<List<BankCard>>(true, StatusCode.OK,"查询成功",list) ;
    }

    @GetMapping("/showCards/{id}")
    public Result<List<Card>> showCards(@PathVariable("id") Integer id) {

        List<Card> cards = bankCardService.showCards(id);
        return new Result<List<Card>>(true, StatusCode.OK,"查询成功",cards);

    }


    @GetMapping("/bankCardUnFreeze/{id}")
    public Result bankCardUnFreeze(@PathVariable("id") Integer id) {
        bankCardService.bankCardUnFreeze(id);
        return new Result(true, StatusCode.OK,"解冻成功");
    }


    @GetMapping("/bankCardFreeze/{id}")
    public Result bankCardFreeze(@PathVariable("id") Integer id) {
        bankCardService.bankCardFreeze(id);
        return new Result(true, StatusCode.OK,"冻结成功");
    }
}
